package com.gugu.procedure.interceptor;

import com.gugu.procedure.common.HttpServletResponseUtils;
import com.gugu.procedure.common.MessageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Component
@Slf4j
public class MyInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        try {
            log.info("请求路径是：{}", request.getRequestURI());

            return true;
        } catch (Exception e) {
            HttpServletResponseUtils.returnErrorResponse(response, MessageResult.error(-1, "Token失效,请重新登录！"));
            return false;
        }
    }
}
